package com.doctcloud.hisinfo.inpbill.controller;

import com.doctcloud.common.core.web.controller.BaseController;
import com.doctcloud.common.core.web.domain.AjaxResult;
import com.doctcloud.common.log.annotation.Log;
import com.doctcloud.common.log.enums.BusinessType;
import com.doctcloud.hisinfo.histable.domain.inpbill.InpBillDetailDo;
import com.doctcloud.hisinfo.inpbill.request.InpBillRequest;
import com.doctcloud.hisinfo.inpbill.service.impl.InpBillDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/inpbill/")
public class InpBillDetailController extends BaseController {
    @Autowired
    private InpBillDetailService billService;

    /**
     * 新增单条费用记录
     * @param data
     * @return
     * @throws IOException
     */
//    @RequiresPermissions("system:inpbill:add")
    @Log(title = "住院费用", businessType = BusinessType.INSERT)
    @PostMapping("/inpbilldetail/add")
    public AjaxResult add(@Validated @RequestBody InpBillDetailDo data) throws IOException {
        int rows = billService.saveItem(data);
        return toAjax(rows);
    }

    /**
     * 查询费用记录(有缓存)
     */
    @PostMapping("/inpbilldetail/listwithcatch")
    public AjaxResult listWithCatch(@Validated @RequestBody InpBillRequest request) throws IOException {
        System.out.println(request.toString());
        List<InpBillDetailDo> list = billService.listItems(request);
        return AjaxResult.success(list);
    }
    /**
     * 查询费用记录(有缓存)
     */
    @PostMapping("/inpbilldetail/list")
    public AjaxResult list(@Validated @RequestBody InpBillRequest request) throws IOException {
        System.out.println(request.toString());
        List<InpBillDetailDo> list = billService.DBListItems(request);
        return AjaxResult.success(list);
    }
    /**
     * 查询患者费用记录
     */
    @GetMapping("/inpbilldetail/listbypat")
    public List<InpBillDetailDo> listByPat(@RequestParam("patientId")String patientId,
                                           @RequestParam("visitId")Integer visitId){
        return billService.DBListByPat(patientId,visitId);
    }
}
